# Definition for singly-linked list.
class ListNode(object):
    def __init__(self, x):
        self.val = x
        self.next = None


class Solution(object):
    def mergeTwoLists(self, l1, l2):
        """
        :type l1: ListNode
        :type l2: ListNode
        :rtype: ListNode
        """
        head = ListNode(0)
        node = head
        while l1 and l2:
            if l1.val < l2.val:
                node.next = l1
                l1 = l1.next
            elif l1.val >= l2.val:
                node.next = l2
                l2 = l2.next
            node = node.next
        node.next = l1 or l2
        return head.next

l1 = ListNode(1)
l2 = ListNode(2)
l3 = ListNode(3)
l4 = ListNode(4)

l1.next = l3
l2.next = l4

s = Solution()
r = s.mergeTwoLists(l1, l2)

i = r
while i:
    print(i.val)
    i = i.next

